﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

namespace NLBS.Blog.blog
{
    public partial class InsertCode : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ActiproSoftware.CodeHighlighter.CodeHighlighterConfiguration config = (ActiproSoftware.CodeHighlighter.CodeHighlighterConfiguration)System.Configuration.ConfigurationManager.GetSection("codeHighlighter");
                foreach (string key in config.LanguageConfigs.Keys)
                {
                    LanguageDropDownList.Items.Add(key);
                }
            }
        }

        protected void HighlightButton_Click(object sender, EventArgs e)
        {
            CodeHighlighter1.Text = CodeTextBox.Text;
            CodeHighlighter1.OutliningEnabled = true;
            CodeHighlighter1.LanguageKey = LanguageDropDownList.SelectedValue;
            CodeHighlighter1.OutliningEnabled = OutliningEnabledCheckBox.Checked;
            CodeHighlighter1.LineNumberMarginVisible = LineNumberMarginVisibleCheckBox.Checked;
        }

        protected void CodeHighlighter1_PostRender(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                string html = CodeHighlighter1.Output;
                html = html.Replace("\r\n", "<br />");
                System.Text.StringBuilder htmlsb = new System.Text.StringBuilder(html);
                htmlsb.Replace("\\", "\\\\");
                htmlsb.Replace("'", "\\\'");
                html = htmlsb.ToString();
                string divstr = "<div style=\\'BORDER-RIGHT: windowtext 0.5pt solid;PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px;PADDING-TOP: 4px;BORDER-LEFT: windowtext 0.5pt solid;WIDTH: 98%; BORDER-BOTTOM: windowtext 0.5pt solid;word-break:break-all\\'>";
                html = divstr + html + "</div>";
                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                sb.Append("<");
                sb.Append("script");
                sb.Append(">");
                sb.Append("var editor=window.dialogArguments;editor.ExecCommand('PasteHTML',false,'" + html + "');window.close();");
                sb.Append("<");
                sb.Append("/");
                sb.Append("script");
                sb.Append(">");
                ScriptOutPut.InnerHtml = sb.ToString();

            }
        }

    }
}
